home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1998 June
/
Macworld (1998-06).dmg
/
Shareware World
/
Info
/
For Developers
/
MacsBug 6.5.4a4
/
Building dcmds
/
C Samples
/
Echo.c
< prev
next >
Wrap
Text File
|
1998-02-11
|
3KB
|
128 lines
/*
File: Echo.c
Contains: A sample dcmd which echos all command line parameters.
Written by: JM3 = Jim Murphy
DAL = Dave Lyons
Copyright: © 1988, 1994, 1996 by Apple Computer, Inc., All Rights Reserved.
Change History (most recent first):
<5> 9/23/96 DAL Honor the "aborted" field in the parameter block, and handle
quoted strings correctly. It's still goofy if you do "echo 0/0",
though (the "if (ok)...else") is not working as expected.
<4> 25-Jan-96 JM3 Added sample build commands.
<3> 10-Dec-94 JM3 Updated for new format 3 dcmd requirements.
<2> 1-Sep-94 JM3 Included string.h so we build with no warnings with -r.
The following MPW commands will build the dcmd and copy it to the "Debugger Prefs" file
in the System folder. The dcmd's name in MacsBug will be the name of the file built by
the Linker.
C Echo.c
Link -o Echo -sg Main=STDCLIB,STDIO,SANELIB dcmdGlue.a.o Echo.c.o" ∂
"{Libraries}Runtime.o" "{CLibraries}StdCLib.o"
BuildDcmd Echo 192 -format3
Echo 'include "Echo";' | Rez -a -o "{SystemFolder}Debugger Prefs"
*/
#include <Memory.h>
#include <Types.h>
#include <string.h>
#include "dcmd.h"
void NumberToHex(long number, Str255 hex)
{
Str255 digits = "0123456789ABCDEF";
int n;
strcpy(hex, &".00000000");
hex[0] = 8;
for (n = 8; n >= 1; n--)
{
hex[n] = digits[number % 16];
number = number / 16;
}
} // NumberToHex
pascal void CommandEntry(dcmdBlock* paramPtr)
{
short pos, ch;
long value;
Boolean ok;
Str255 str;
static const char usageStr[] = "\p[params...]";
switch (paramPtr->request)
{
case dcmdInit:
break;
case dcmdHelp:
dcmdDrawLine("\pEcho the command line parameters");
break;
case dcmdGetInfo:
* (long *) &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->dcmdVersion = 0x03008000; // version 3.0 final
BlockMoveData(&usageStr, &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->usageStr, usageStr[0]+1);
break;
case dcmdDoIt:
do
{
// Save the position so we can rewind if we get an error
pos = dcmdGetPosition();
ch = dcmdPeekAtNextChar();
if (((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')) || (ch == '"') || (ch == '\''))
{
// Get the parameter as a text string
ch = dcmdGetNextParameter(str);
dcmdDrawLine(str);
}
else
{
// Get the parameter as a 32 bit value
ch = dcmdGetNextExpression(&value, &ok);
if (ok)
{
// The expression was parsed correctly
NumberToHex(value, str);
dcmdDrawLine(str);
}
else
{
// The expression contained an error. Get it as a string
dcmdSetPosition(pos);
ch = dcmdGetNextParameter(str);
dcmdDrawLine(str);
}
}
} while (ch != '\n' && !paramPtr->aborted);
break;
// Version 3 and newer dcmds must quietly ignore requests we don't recognize.
default:
break;
}
} // CommandEntry